<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改事项')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: ztree-css" />


    <link rel="stylesheet" th:href="@{/css/sku_style.css}"/>
    <style>
        body{height:auto;font-family: "Microsoft YaHei";}
        button{font-family: "SimSun","Helvetica Neue",Helvetica,Arial;}
        .ztree{
            position: absolute;
            z-index: 888;
            background-color: #eee;
            border: 1px solid #ccc;
            overflow: auto;
            width: 150px;
            min-height: 50px;
            max-height: 300px;
        }
        #tree_1{
            margin-left: -20px;
        }
        .tree_div,.mytree_div{
            position: relative;
        }

        .caret1,.caret2{
            float: right;
            position: absolute;
            margin-left: -15px;
            top: 10px;
        }
    </style>
</head>
<body class="white-bg">
<div class="container-div">
    <div class="demo-title">项目--审核事项</div>

    <div id="skuTable">
        <table class="skuTable">
            <thead>
            <tr>
                <th style="width: 80px;">序号</th>
                <th style="width: 130px;">办理流程</th>
                <th style="display: none">typeId</th>
                <th style="display: none">id</th>
                <th style="display: none">sort</th>
                <th style="width: 210px;">办理事项</th>
                <th style="display: none">orgStatus</th>
                <!--<th style="width: 150px;">单位类型</th>-->
                <th style="width: 150px;">负责部门</th>
                <th style="width: 150px;">负责人</th>
                <th style="width: 180px;">计划完成时间</th>
                <th style="width: 95px;">红灯预警天数</th>
                <th style="width: 95px;">黄灯预警天数</th>

                <th th:if="${flasAuditOrView == 'true' ? true : flase}" style="width: 180px;">操作</th>
            </tr>
            </thead>
            <tbody id="mytbody">

            </tbody>
        </table>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: ztree-js" />

<script th:inline="javascript">
    var prefix = ctx + "linkong/project";
    var proId = [[${proId}]];
    var mydata = {};
    $(function (){
        $.ajax({
            url: prefix + "/selectMattersByIds",
            type: 'POST',
            data: {ids:0,proId:proId},
            async: false,
            success: function (data) {
                mydata = data;
            }
        })
        listShow();
    })

    // $(document).ready(function () {
    //     $(".MALL").hide();
    //     $(".MHover").mouseover(function (e) {
    //         $(this).next(".MALL").css({"position":"absolute","top":e.pageY+9,"left":e.pageX+9}).show();
    //     });
    //     $(".MHover").mousemove(function (e) {
    //         $(this).next(".MALL").css({ "color": "#696969", "position": "absolute", "opacity": "0.9", "background-color": "666", "top": e.pageY + 9, "left": e.pageX + 9 });
    //     });
    //     $(".MHover").mouseout(function () {
    //         $(this).next(".MALL").hide();
    //     });
    // });


    function listShow() {
        var userRole = [[${@permission.getPrincipalProperty('roleKey')}]];
        var str = "";
        var index = 1;
        if(JSON.stringify(mydata) == '{}'){
            str = '<tr><td colspan="9"><div style="display: block;text-align: center;">没有找到匹配的记录</div></td></tr>'
        }else{
            for(var obj in mydata ){
                var myarr = mydata[obj];
                var len = myarr.length;
                str += '<tr>'
                    + '<td rowspan='+ len +'>'+ index + '</td>'
                    + '<td rowspan='+ len + '>'+ obj + '</td>';
                $.each(myarr, function (i, value){

                    // var proTypeName = value.orgStatus == '0'?'企业':'部门';
                    str += '<td style="display: none" class="type_id">' + value.typeId + '</td>'
                        + '<td style="display: none" class="item_id">' + value.id + '</td>'
                        + '<td style="display: none" class="sort">' + value.sort + '</td>'
                        + '<td class="m_name">'+ value.name + '</td>'
                        + '<td style="display: none" class="orgStatus"> '+ value.orgStatus +  '</td>'
                        /* + '<td >' + proTypeName+'</td>'*/
                        + '<td class="mainOrgname">'+ value.mainOrgname +'</td>'
                        + '<td class="approveUser">'+ value.approveUsername + '</td>'
                        + '<td class="expectedDate">'+ value.expectedDate.substr(0,10) +'</td>'
                        + '<td class="redLightDays">'+ value.redLightDays +'</td>'
                        + '<td class="yelLightDays" >'+ value.yelLightDays +'</td>'
                    // + '<td >';

                        if ([[${flasAuditOrView}]] == "true"){
                            str += '<td >';
                            if(value.status != '1' && userRole == "peojectAdmin"){//审核未通过且不为企业角色
                                str += '<a href="javascript:;" style="color: #0d8ddb" class="audit_tr_btn" onclick="audit_btn(' + value.id + ',' + '\'' + value.projectId + '\')">审核</a> &nbsp;&nbsp;';
                            }
                            if(value.filePath == null || value.filePath == "" && userRole == "dept" || userRole == "company"  && value.status == '2'){//未上传
                                str += '<a href="javascript:;" style="color: #0d8ddb" class="upload_tr_btn" onclick="upload('+ value.id + ',' + '\' '+ value.projectId + '\')">上传</a> &nbsp;&nbsp;';
                            } else if(value.filePath != null && value.filePath != ""){//已上传
                                str += '<a href="javascript:;" style="color: #0d8ddb" class="download_tr_btn" onclick="downloadFile('+ value.id + ',' + '\' '+ value.projectId + '\')">下载</a> &nbsp;&nbsp;';
                            }
                            str += '<a href="javascript:;" style="color: #0d8ddb" class="download_tr_btn" onclick="guideView('+ value.id + ',' + '\' '+ value.projectId + '\')">事项指南</a>'
                                +'</td >';
                        }
                        str += '</tr>';

                })
                index += 1;
            }
        }

            $("#mytbody").html(str);
        $("input[name='onlineTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    }
    //审核
    function audit_btn(id,proId) {
	    var url = ctx + "linkong/matterProject/auditStatus/" + id + "?projectId=" + proId;
        $.modal.open("审核", url, '800', '300');
	}

  	//上传文件
    function upload(id,proId) {
         var url = ctx + "linkong/matterProject/uploadView/"+id + "?projectId=" + proId;
         $.modal.open("上传", url, '500', '200');
    }

    //事项指南
    function guideView(id,proId) {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
        parent.layer.open({
            type: 2,
            area: [1000 + 'px', 500 + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: '办事指南',
            content: "/linkong/matterProject/guideView/"+id + "?projectId=" + proId,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: true,
            cancel: function(index) {
                return true;
            }
        });
    }

    //下载
    function downloadFile(id,proId) {
        var data = new FormData();
        data.append("id",id);
        data.append("projectId",proId);
        $.ajax({
            type: "POST",
            url: ctx + "linkong/matterProject/getMatterProject",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function(result) {

                if (result.code == 0) {
                    window.location.href = ctx + "common/download2?fileName="+result.fileName;
                } else {
                    $.modal.alertError(result.msg);
                }
            }
        });
	}


    function submitHandler() {
        $.modal.close();
    }

</script>

</body>
</html>